﻿#pragma once

#include <qobject.h>
#include <qdatetime.h>
#include <qfile.h>
#include <qthread.h>

class LogSaver1;
class LogSaver : public QObject
{
  Q_OBJECT
public:
  enum LogFlag
  {
    Debug = 0x01,
    Information = 0x02,
    Warning = 0x04,
    Critical = 0x08
  };
private:
  int logLevel = Critical | Warning | Information;
  QString logFilePath = "MemsAutoTestSoftware_Log.log";
  QString newLine = "\r\n";
  QString QString_debug = "(Debug)";
  QString QString_information = "(Information)";
  QString QString_warning = "(Warning)";
  QString QString_critical = "(Critical)";
  QFile* qfile = Q_NULLPTR;
public:
  LogSaver(QObject* parent = Q_NULLPTR);
  ~LogSaver();
signals:
  void signal_writeLogToFile(QString msg, QFile* file);
public:
  void saveLog(QString msg, LogFlag logFlag);
  void enableLogLevel(LogFlag logFlag);//log level control
  void disableLogLevel(LogFlag logFlag);//log level control
  QString getQStringOfLogFlag(LogSaver::LogFlag logFlag);
public://geter and seter
  int getLogLevel();
  QString getLogFilePath();
  void setLogFilePath(QString filePath);
};

class LogSaver1 :public QObject
{
  Q_OBJECT
private:
  friend class  LogSaver;
private:
  LogSaver1();
  ~LogSaver1();
private slots:
  void slot_writeLogToFile(QString msg, QFile* file);
};
